package com.firemoss.atonement.test.metadata.inspectors.entity
{
	import com.firemoss.atonement.metadata.AtonementMetadata;
	import com.firemoss.atonement.metadata.DefaultMetadataBuilder;
	import com.firemoss.atonement.metadata.EntityMetadata;
	import com.firemoss.atonement.metadata.IMetadataBuilder;
	import com.firemoss.atonement.test.metadata.inspectors.entity.impl.CacheManagementStrategyImpl;
	import com.firemoss.atonement.test.metadata.inspectors.entity.objects.*;
	
	import org.flexunit.asserts.*;

	public class EntityInspectorTests
	{		
		private var metadataBuilder:IMetadataBuilder = new DefaultMetadataBuilder();
		
		/*
		[Test]
		public function default_cache_management_strategy_factory_returns_correct_strategies() : void
		{
			// Include the class to get it in our swf!
			var foo :CacheManagementStrategyImpl = new CacheManagementStrategyImpl()
				
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new CacheManagementTestObject() );
			var emd : EntityMetadata = md.entityMetadata
			
			assertNotNull( emd )
			
			assertNull( emd.getManagementStrategyFor( "somethingElse" ) );
			assertTrue( emd.getManagementStrategyFor( "collection" ) is ListCacheManagementStrategy )
			assertTrue( emd.getManagementStrategyFor( "dict" ) is DictionaryCacheManagementStrategy )
			assertTrue( emd.getManagementStrategyFor( "entity" ) is EntityCacheManagementStrategy )
			assertTrue( emd.getManagementStrategyFor( "other" ) is CacheManagementStrategyImpl)
			
		}
		*/
		
		[Test]
		public function objects_marked_entities_can_be_inspected() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new TestEntity() );
			
			assertNotNull( md.entityMetadata );
		}
		
		[Test]
		public function objects_not_marked_entities_get_no_entity_metadata() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new NotAnEntity() );
			
			assertNull( md.entityMetadata );
		}
			
		[Test]
		public function can_determine_identifier_from_annotation_on_property_and_prefers_it_to_convention() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new IdAnnotatedEntity() );
			
			// Using odd capitalization to test case-insensitivity
			assertTrue( md.entityMetadata.idPropertyName == "identity" );
		}
		
		[Test]
		public function can_determine_identifier_from_annotation_on_getter_and_prefers_it_to_convention() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new IdAnnotatedGetterEntity() );
			
			// Using odd capitalization to test case-insensitivity
			assertTrue( md.entityMetadata.idPropertyName == "identity" );
		}
		
		[Test]
		public function can_conventionally_determine_identifier_when_named_id_and_prefers_it_to_classNameId() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new IdEntity() );
			
			// Using odd capitalization to test case-insensitivity
			assertTrue( md.entityMetadata.idPropertyName == "iD" );
		}
		
		[Test]
		public function can_conventionally_determine_identifier_when_named_classNameId() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new ClassNameIdEntity() );
			
			// Using odd capitalization to test case-insensitivity
			assertTrue( md.entityMetadata.idPropertyName == "classNAMEIdEntityId" );
		}
		
		[Test]
		public function can_conventionally_determine_identifier_when_getter_named_id_and_prefers_it_to_classNameId() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new IdGetterEntity() );
			
			// Using odd capitalization to test case-insensitivity
			assertTrue( md.entityMetadata.idPropertyName == "iD" );
		}
		
		[Test]
		public function can_conventionally_determine_identifier_when_getter_named_classNameId() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new ClassNameIdGetterEntity() );
			
			// Using odd capitalization to test case-insensitivity
			assertTrue( md.entityMetadata.idPropertyName == "classNAMEIdGetterEntityId" );
		}
		
		[Test]
		public function entity_name_determined_conventionally() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new IdEntity() );
			
			assertTrue( md.entityMetadata.entityName == "IdEntity" );
		}
		
		[Test]
		public function entity_name_can_be_set_via_annotation() : void
		{
			var md : AtonementMetadata = metadataBuilder.buildMetadata( new IdGetterEntity() );
			
			assertTrue( md.entityMetadata.entityName == "CustomNamedIdGetterEntity" );
		}
		
	}
}